//
// Created by Administrator on 2023/5/31.
//

#pragma once
#include "../header/LDF_Table.h"


LDF_Table::LDF_Table():
    Null_Table(true), table_model(new QStandardItemModel())
{
    this->table_model->setItem(0, 0, new QStandardItem());
    this->setModel(this->table_model);
}


LDF_Table::LDF_Table(int rows, int columns):
    rows(rows), columns(columns), Null_Table(false)
    , table_model(new QStandardItemModel())
{
    for(int row {0}; row < this->rows; row++)
    {
        for(int column {0}; column < this->columns; column++)
        {
            this->table_model->setItem(row, column, new QStandardItem());
        }
    }
    this->setModel(this->table_model);
}


LDF_Table::~LDF_Table()
{
    delete table_model;
}


void LDF_Table::Set_Item_Count(qint32 rows, qint32 columns)
{
    if (this->Null_Table)
    {
        this->rows = rows;
        this->columns = columns;
        for(int row {0}; row < this->rows; row++)
        {
            for(int column {0}; column < this->columns; column++)
            {
                this->table_model->setItem(row, column, new QStandardItem());
            }
        }
        this->setModel(this->table_model);
    }
}


QStandardItemModel* LDF_Table::Get_Model()
{
    return this->table_model;
}


void LDF_Table::Redraw(int width, int height)
{
    this->resize(width - 10, height - 50);
    this->move(5, 30);
}


void LDF_Table::Add_Vector(QVector<QVector<QString>> QVec)
{
    for (int i {0}; i < QVec.length(); i++)
    {
        for (int j {0}; j < QVec[i].length(); j++)
        {
            this->table_model->setItem(i, j, new QStandardItem(QVec[i][j]));
        }
    }
    this->setModel(this->table_model);
}
